use rstest::rstest;

use super::super::*;
use crate::tests::fixtures::{rand_usize, random_connectors, RANDOM_USIZE};

#[test]
fn test_connectors_raw_initialization() {
    let north = rand_usize(0, 100);
    let east = rand_usize(0, 10000);
    let south = rand_usize(0, 10);
    let west = rand_usize(0, 1000);
    let connectors = Connectors {
        north,
        east,
        south,
        west,
    };

    assert_eq!(connectors.north, north);
    assert_eq!(connectors.east, east);
    assert_eq!(connectors.south, south);
    assert_eq!(connectors.west, west);
}

#[rstest]
#[case::north(Direction::North, *RANDOM_USIZE + 2)]
#[case::east(Direction::East, *RANDOM_USIZE + 3)]
#[case::south(Direction::South, *RANDOM_USIZE + 4)]
#[case::west(Direction::West, *RANDOM_USIZE + 5)]
fn test_connectors_get_connector(#[case] side: Direction, #[case] expected_connector_id: usize) {
    let connectors = Connectors {
        north: *RANDOM_USIZE + 2,
        east: *RANDOM_USIZE + 3,
        south: *RANDOM_USIZE + 4,
        west: *RANDOM_USIZE + 5,
    };
    let connector_id: usize = connectors.get_connector(side);
    assert_eq!(expected_connector_id, connector_id);
}

#[rstest]
#[case::north(Direction::North)]
#[case::east(Direction::East)]
#[case::south(Direction::South)]
#[case::west(Direction::West)]
fn test_connectors_set_connector(
    #[case] side: Direction,
    #[values(true, false)] change_field: bool,
) {
    let mut connectors = random_connectors();
    let connectors_clone = connectors.clone();
    let value = if change_field {
        rand_usize(1, 100)
    } else {
        connectors.get_connector(side)
    };

    let _: () = connectors.set_connector(side, value);

    if change_field {
        assert_eq!(connectors.get_connector(side), value);
    } else {
        assert_eq!(connectors, connectors_clone);
    }
}
